#!/bin/bash
# Installe Python2.7 en complément sur CentOS
#
# Installer les dépendances
yum install -y sqlite sqlite-devel gcc gdbm-devel readline-devel ncurses-devel zlib-devel bzip2-devel sqlite-devel db4-devel openssl-devel tk-devel bluez-libs-devel wget make

# Installer python 2.7 avec threads et librairies partagées
cd /usr/src
wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
tar xvzf Python-2.7.2.tgz
cd Python-2.7.2/
./configure --with-threads --enable-shared
make && make altinstall
cat > /etc/ld.so.conf.d/opt-python2.7.conf << EOF
/usr/local/lib
EOF
ldconfig
if [[ ! -a /root/.zshrc ]]
then
    touch /root/.zshrc
fi

echo "alias python=$(which python2.7)" >> /root/.zshrc


# Installer apache2, mod_wsgi et mod_x_sendfile
cd /usr/src
yum install -y httpd{,-devel}
wget http://modwsgi.googlecode.com/files/mod_wsgi-3.3.tar.gz
tar xvzf mod_wsgi-3.3.tar.gz
cd mod_wsgi-3.3/
./configure --with-python=/usr/local/bin/python2.7
make && make install
cd /usr/src

if [ "$(uname -m)" = "x86_64" ]
then
    lib_path="lib64"
else
    lib_path="lib"
fi

echo "LoadModule wsgi_module /usr/$lib_path/httpd/modules/mod_wsgi.so" > /etc/httpd/conf.d/mod_wsgi.conf

# active les hôtes virtuels nommés ( pas ici -> lors de la création des virtualhost dans start_django_project
# sed -i "s/^#\(NameVirtualHost.*\)/\1/" /etc/httpd/conf/httpd.conf
service httpd restart

cd /usr/src

wget --no-check-certificate https://tn123.org/mod_xsendfile/mod_xsendfile.c
apxs -cia mod_xsendfile.c

echo "XSendFile on
XSendFilePath /usr/local/django" > /etc/httpd/conf.d/mod_xsendfile.conf
service httpd restart

# Installer Django 1.3.1
cd /usr/src
wget http://www.djangoproject.com/download/1.3.1/tarball/
tar xvzf Django-1.3.1.tar.gz
cd Django-1.3.1
python2.7 setup.py install

cd /usr/src
wget "http://docutils.svn.sourceforge.net/viewvc/docutils/trunk/docutils/?view=tar" -O docutils-snapshot.tgz
tar xvzf docutils-snapshot.tgz
cd docutils
python2.7 setup.py install
